package rsj.db;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import common.util.prop.PropUtils;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
@Deprecated
public class MyDataSource {

    public static HikariDataSource ds;

    static {
        createDataSource();
    }

    /**
     * 初始化数据库连接池：默认10
     */
    public static void createDataSource() {
        Properties properties = PropUtils.loadFile("rsjdb.properties");
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl(properties.getProperty("url"));
        config.setUsername(properties.getProperty("user"));
        config.setPassword(properties.getProperty("password"));
        config.setConnectionTestQuery("SELECT 1");
        ds = new HikariDataSource(config);
    }

    public static Connection getConnection() {
        Connection connection;
        try {
            connection =  ds.getConnection();
        } catch (SQLException exception) {
            throw new RuntimeException("获取数据库连接失败！");
        }
        return connection;
    }

}
